package com.example.zhihuhelpapp.activity;

import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.example.zhihuhelpapp.R;
import com.example.zhihuhelpapp.base.BaseActivity;
import com.example.zhihuhelpapp.utils.CoreConstant;
import com.example.zhihuhelpapp.utils.SpUtils;
import com.example.zhihuhelpapp.utils.UIUtils;

/**
 * 添加京东key与Secret的
 */
public class InputJingDongKeyActivity extends BaseActivity {
    private EditText et_jd_key;
    private EditText et_jd_secret;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_input_jingdong_key;
    }

    @Override
    protected void initView() {
        showToolBar(true, getString(R.string.setting));
        et_jd_key = findViewById(R.id.et_jd_key);
        et_jd_secret = findViewById(R.id.et_jd_secret);

        String jdAppKey = SpUtils.getInstance().get(CoreConstant.SpConstant.KEY_JD_APP_KEY, "");
        String jdAppSecret = SpUtils.getInstance().get(CoreConstant.SpConstant.KEY_JD_APP_SECRET, "");

        if (!TextUtils.isEmpty(jdAppKey)) {
            et_jd_key.setText(jdAppKey);
        }
        if (!TextUtils.isEmpty(jdAppSecret)) {
            et_jd_secret.setText(jdAppSecret);
        }
    }

    public void confirm(View view) {
        String appKey = et_jd_key.getText().toString().trim();
        String appSecret = et_jd_secret.getText().toString().trim();
        if (TextUtils.isEmpty(appKey) || TextUtils.isEmpty(appSecret)) {
            UIUtils.showToast("内容不能为空");
            return;
        }
        SpUtils.getInstance().put(CoreConstant.SpConstant.KEY_JD_APP_KEY, appKey);
        SpUtils.getInstance().put(CoreConstant.SpConstant.KEY_JD_APP_SECRET, appSecret);
        finish();
    }
}
